/**
 * Created by tuyan on 2017/1/9.
 */
window.Cherry.cookies = {};
$.extend(window.Cherry.cookies, {
    get: function(_key) {
        var arr, reg = new RegExp("(^| )" + _key + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg))
            return encodeURIComponent(arr[2]);
        else
            return null;
    },
    set: function(_key, _val, _expires) {
        if (!_expires) {
            _expires = new Date();
            _expires.setTime(_expires.getTime() + 12 * 3600 * 1000);
        } else if (_expires == -1) {
            _expires = new Date();
            _expires.setTime(_expires.getTime() - 1000);
        }
        _expires = _expires.toGMTString();
        // 正常
        document.cookie = _key + "=" + _val + "; expires=" + _expires + "; path=/";
    },
    remove: function(_key) {
        this.set(_key, "", -1);
    }
});